//
//  CaptureViewController.swift
//  SHMediaTools_Example
//
//  Created by ace on 2023/6/21.
//  Copyright © 2023 CocoaPods. All rights reserved.
//

import UIKit
import SHMediaTools
import AVFoundation

class CaptureViewController: UIViewController {

    let videoCapture = SHVideoCapture.sharedInstance
//    lazy var videoCapture = SHVideoCapture()
    
    private let videoDecoder = SHVideoEncoder(width: 640, height: 480, bitRate: 480 * 640 * 3 * 4, fps: 10)
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
//        let asd = SHMediaTools.
//        let videoCapture = SHMediaTools.sharedInstance;
//        let videoCapture = SHVideoCapture.sharedInstance
        
        
//        let typeArr: [AVMediaType] = [.video, .audio]
//        for type in typeArr {
//            SHVideoCapture.requestAccessMedia(type)
//        }
        
        view.backgroundColor = .white
        view.layer.addSublayer(videoCapture.previewLayer)
        
        let ratio: CGFloat = 30
        videoCapture.previewLayer.frame = CGRectMake(0, 60, 9*ratio, 16*ratio)
        
        videoCapture.startCapture { sampleBuffer in
            weak var weakSelf = self
            weakSelf?.videoDecoder.encodeVideo(sampleBuffer: sampleBuffer);
        }
        
        self.videoDecoder.videoEncodeCallBackSPSAndPPS = { spsData, ppsData in
//            print("sps: \(spsData)")
        }
        
        self.videoDecoder.videoEncodeCallback = { naluData in
//            print("naluData: \(naluData)")
        }
        
    }

}
